package cn.tedu.ivos.application.controller;

import cn.tedu.ivos.application.pojo.dto.ApplicationQuery;
import cn.tedu.ivos.application.pojo.dto.ApplicationSaveParam;
import cn.tedu.ivos.application.pojo.vo.ApplicationVO;
import cn.tedu.ivos.application.service.ApplicationService;
import cn.tedu.ivos.base.response.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.Jar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/application")
public class ApplicationController {
    @Autowired
    ApplicationService applicationService;
    @PostMapping("save")
    public JsonResult saveApplication(ApplicationSaveParam applicationSaveParam){
        log.debug("保存申请单:applicationParam={}",applicationSaveParam);
        applicationService.save(applicationSaveParam);
        return JsonResult.ok();
    }

    @GetMapping("select")
    public JsonResult select(ApplicationQuery applicationQuery){
        log.debug("查询申请单:applicationQuery={}",applicationQuery);
        List<ApplicationVO> applicationVOS = applicationService.select(applicationQuery);
        return JsonResult.ok(applicationVOS);
    }

    @PostMapping("cancel/{id}")
    public JsonResult cancel(@PathVariable Long id){
        log.debug("撤销申请单:id={}",id);
        applicationService.cancel(id);
        return JsonResult.ok();
    }
}
